package com.draw.server.event;

import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class SelectionChange implements ListSelectionListener {
	private JTextField wordField;
	private JSpinner difficultyField;
	private JTable jTable;
	
	public SelectionChange(JTable jTable, JTextField wordField, JSpinner difficultyField) {
		this.jTable = jTable;
		this.wordField = wordField;
		this.difficultyField = difficultyField;
	}
	
	@Override
	public void valueChanged(ListSelectionEvent e) {
		if (e.getSource() == jTable.getSelectionModel()
	              && jTable.getRowSelectionAllowed() && this.jTable.getSelectedRow() != -1) {
		
		this.wordField.setText((String) this.jTable.getModel().getValueAt(this.jTable.getSelectedRow(), 0));
		this.difficultyField.setValue(Integer.parseInt((String) this.jTable.getModel().getValueAt(this.jTable.getSelectedRow(), 1))); 
	
		}

	}	
}
